/*! 
 * Vcol Compoment is super class of all componet
 */
(function(){
	this.Component = Class.extend({
		init:function(opts){
			this.opts = $.extend({},this.defaultopts,opts);
			this.$e = $("#"+opts.id);// id must specified
			this.$c= $(window);//container default is the window
			//component class "vcolcomponent"
			//container class "vcolcontainer"
			//find the nearest vcol container
			var cur = this.$e[0];
			while(cur!=document.body && cur.className.indexOf("vcolcontainer")==-1){
				cur= cur.parentNode;
			}
			if(cur!=document.body){this.$c= $(cur);}
			//fix IE 6/7 window resize bug 
			//see http://blog.csdn.net/cheng5128/archive/2010/04/15/5501879.aspx
			if (!+"\v1" && !document.querySelector && this.$c[0]==window) { // for IE6 IE7
				this.$c=$(document.body);
			}
			//trigger size when parent container resize
			var c = this;
			if(this.$c[0]==window || this.$c[0]==document.body){
				this.$c.resize(function(){c.size.apply(c);});
			}else{
				this.$c.bind("vcolresize",function(){//vcol resize event triggered by vcolcontainer
					c.size.apply(c);
				});
			}
		},
		defaultopts:{},
		size:function(){
			if(this.opts.width) this.$e.width(this.opts.width);
			if(this.opts.height) this.$e.height(this.opts.height);
		},
		fireEvent:function(eventName,eventdata,originEvent,fn){
			//before event 
			if(typeof(this.opts["onBefore"+eventName.capFirst()])=="function"){
				//before event prevent default action if return false
				if(!this.opts["onBefore"+eventName.capFirst()].apply(this,[originEvent,eventdata])){return ;}
			}
			//vcol self handle event 
			fn.apply(this,[originEvent,eventdata]);
			//trigger option handler
			if(typeof(this.opts["on"+eventName.capFirst()])=="function"){
				this.opts["on"+eventName.capFirst()].apply(this,[originEvent,eventdata]);
			}
			this.$e.trigger(eventName,eventdata);//trigger the jq event
		}
	});
})();
